package com.huhao.wshare.service.impl;

import com.huhao.wshare.entity.User;
import com.huhao.wshare.repository.UserRepository;
// 修改点：导入新的 CustomUserDetails
import com.huhao.wshare.service.security.CustomUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    private final UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String account) throws UsernameNotFoundException {
        User user = userRepository.findByAccount(account)
                .orElseThrow(() -> new UsernameNotFoundException("用户不存在: " + account));

        // 修改点：返回我们自定义的 UserDetails 实现，它包含了完整的 User 对象
        return new CustomUserDetails(user);
    }
}
